package hut.game.actor;

import android.util.Log;
import hut.game.table.NuocDi;
import hut.game.table.VanCo;

public class Eval {
	
	public static int TinhDiemBanCo(NuocDi mNuocDi){
		Gen.MakeMove(mNuocDi);
		int tong = 0, max = 0, min = 0;
		if (!VanCo.state) {
			for(int i = 0; i < VanCo.computer.dsQuanCo.size(); i++){
				max +=  (VanCo.computer.dsQuanCo.get(i)).getDiem();
			}

			for(int i = 0; i < VanCo.n1.dsQuanCo.size(); i++){
				min +=  (VanCo.n1.dsQuanCo.get(i)).getDiem();
			}
		}
		tong = max - min;
		Log.d("min", "max/min " + max+"/"+min + "/" + tong);
		Gen.UnMakeMove(mNuocDi);
		return tong;
	}
	
	public static int TinhTongDiemBanCo() {
		int tong = 0, max = 0, min = 0;
		if (!VanCo.state) {
			for(int i = 0; i < VanCo.computer.dsQuanCo.size(); i++){
				max +=  (VanCo.computer.dsQuanCo.get(i)).getDiem();
			}

			for(int i = 0; i < VanCo.n1.dsQuanCo.size(); i++){
				min +=  (VanCo.n1.dsQuanCo.get(i)).getDiem();
			}
		}
		tong = max - min;
		Log.d("min", "max/min " + max+"/"+min + "/" + tong);
		return  tong;
	}

	public static int Bonous() {
		int[][] bonous = { { -2, -3, -3, -4, -4, -5, 0 }, /* Chot, Sy, Tinh, Ma, Phao, Xe, Tuong - Quan Do */
						   { -2, -3, -3, -4, -4, -5, 0 } /* Chot, Sy, Tinh, Ma, Phao, Xe, Tuong - Quan Den */
						 };
		int diemthuong = 0;

		// Tang diem cho quan doi phuong khi khuyet sy, tinh va tru diem khi xe,
		if (VanCo.n1.qSy[0].TrangThai == 0 || VanCo.n1.qSy[1].TrangThai == 0) {
			bonous[0][5] += 4; // Tang diem cho xe, ma, chot
			bonous[0][3] += 2;
			bonous[0][0] += 1;
		}
		if (VanCo.n1.qTinh[0].TrangThai == 0
				|| VanCo.n1.qTinh[1].TrangThai == 0) {
			bonous[0][5] += 2; /* Tang diem cho xe, phao, chot */
			bonous[0][4] += 2;
			bonous[0][0] += 1;
		}
		if (VanCo.computer.qSy[0].TrangThai == 0
				|| VanCo.computer.qSy[1].TrangThai == 0) {
			bonous[1][5] += 4; // Tang diem cho xe, ma, chot
			bonous[1][3] += 2;
			bonous[1][0] += 1;
		}
		if (VanCo.computer.qTinh[0].TrangThai == 0
				|| VanCo.computer.qTinh[1].TrangThai == 0) {
			bonous[1][5] += 2; /* Tang diem cho xe, phao, chot */
			bonous[1][4] += 2;
			bonous[1][0] += 1;
		}

//		if ((VanCo.n1.qXe[0].Hang == 9 && VanCo.n1.qXe[0].Cot == 0)
//				&& (VanCo.n1.qMa[0].Hang == 9 && VanCo.n1.qMa[0].Cot == 1))
//			bonous[1][6] -= 10;
//		if ((VanCo.n1.qXe[1].Hang == 9 && VanCo.n1.qXe[1].Cot == 8)
//				&& (VanCo.n1.qMa[1].Hang == 9 && VanCo.n1.qMa[1].Cot == 7))
//			bonous[1][6] -= 10;
//		if ((VanCo.computer.qXe[0].Hang == 0 && VanCo.computer.qXe[0].Cot == 0)
//				&& (VanCo.computer.qMa[0].Hang == 0 && VanCo.computer.qMa[0].Cot == 1))
//			bonous[0][6] -= 10;
//		if ((VanCo.computer.qXe[1].Hang == 0 && VanCo.computer.qXe[1].Cot == 8)
//				&& (VanCo.computer.qMa[1].Hang == 0 && VanCo.computer.qMa[1].Cot == 7))
//			bonous[0][6] -= 10;

		int[][] count = { { 0, 0, 0, 0, 0, 0, 0 }, /* Chot, Sy, Tinh, Ma, Phao, Xe, Tuong - Quan Do */
						  { 0, 0, 0, 0, 0, 0, 0 } }; /* Chot, Sy, Tinh, Ma, Phao, Xe, Tuong - Quan Den */

		if (VanCo.computer.qXe[0].TrangThai != 0)
			count[0][5] += 1;
		if (VanCo.computer.qXe[1].TrangThai != 0)
			count[0][5] += 1;
		if (VanCo.computer.qPhao[0].TrangThai != 0)
			count[0][4] += 1;
		if (VanCo.computer.qPhao[1].TrangThai != 0)
			count[0][4] += 1;
		if (VanCo.computer.qMa[0].TrangThai != 0)
			count[0][3] += 1;
		if (VanCo.computer.qMa[1].TrangThai != 0)
			count[0][3] += 1;
		if (VanCo.computer.qTinh[0].TrangThai != 0)
			count[0][2] += 1;
		if (VanCo.computer.qTinh[1].TrangThai != 0)
			count[0][2] += 1;
		if (VanCo.computer.qSy[0].TrangThai != 0)
			count[0][1] += 1;
		if (VanCo.computer.qSy[1].TrangThai != 0)
			count[0][1] += 1;
		if (VanCo.computer.qChot[0].TrangThai != 0)
			count[0][0] += 1;
		if (VanCo.computer.qChot[1].TrangThai != 0)
			count[0][0] += 1;
		if (VanCo.computer.qChot[2].TrangThai != 0)
			count[0][0] += 1;
		if (VanCo.computer.qChot[3].TrangThai != 0)
			count[0][0] += 1;
		if (VanCo.computer.qChot[4].TrangThai != 0)
			count[0][0] += 1;

		if (VanCo.n1.qXe[0].TrangThai != 0)
			count[1][5] += 1;
		if (VanCo.n1.qXe[1].TrangThai != 0)
			count[1][5] += 1;
		if (VanCo.n1.qPhao[0].TrangThai != 0)
			count[1][4] += 1;
		if (VanCo.n1.qPhao[1].TrangThai != 0)
			count[1][4] += 1;
		if (VanCo.n1.qMa[0].TrangThai != 0)
			count[1][3] += 1;
		if (VanCo.n1.qMa[1].TrangThai != 0)
			count[1][3] += 1;
		if (VanCo.n1.qTinh[0].TrangThai != 0)
			count[1][2] += 1;
		if (VanCo.n1.qTinh[1].TrangThai != 0)
			count[1][2] += 1;
		if (VanCo.n1.qSy[0].TrangThai != 0)
			count[1][1] += 1;
		if (VanCo.n1.qSy[1].TrangThai != 0)
			count[1][1] += 1;
		if (VanCo.n1.qChot[0].TrangThai != 0)
			count[1][0] += 1;
		if (VanCo.n1.qChot[1].TrangThai != 0)
			count[1][0] += 1;
		if (VanCo.n1.qChot[2].TrangThai != 0)
			count[1][0] += 1;
		if (VanCo.n1.qChot[3].TrangThai != 0)
			count[1][0] += 1;
		if (VanCo.n1.qChot[4].TrangThai != 0)
			count[1][0] += 1;

		for (int i = 0; i <= 5; i++) {
			diemthuong += count[0][i] * bonous[0][i] - count[1][i]* bonous[1][i];
		}
		// Tru diem khi mat quan
		diemthuong += bonous[0][6] - bonous[1][6];
		return diemthuong;
	}
	
	

}
